package com.band.controller;

import com.band.entity.PageBean;
import com.band.entity.Result;
import com.band.entity.Student;
import com.band.entity.StudentQueryParam;
import com.band.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 条件分页查询
     * @param param
     * @return
     */
    @GetMapping
    public Result list(StudentQueryParam param){
        log.info("查询参数：{}", param);
        PageBean pageBean = studentService.list(param);
        return Result.success(pageBean);
    }

    /**
     * 删除员工
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("删除员工：{}", ids);
        studentService.delete(ids);
        return Result.success();
    }

    /**
     * 新增员工
     * @param student
     * @return
     */
    @PostMapping
    public Result insert(@RequestBody Student student){
        log.info("新增员工：{}", student);
        studentService.insert(student);
        return Result.success();
    }

    /**
     * 数据回显
     * @param
     * @return
     */
    @GetMapping("/{id}")
    public Result select(@PathVariable Integer id){
        log.info("查询员工：{}", id);
        Student student = studentService.select(id);
        return Result.success(student);
    }

    /**
     * 修改员工
     * @param
     * @return
     */
    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("修改员工：{}", student);
        studentService.update(student);
        return Result.success();
    }

    @PutMapping("/violation/{id}/{score}")
    public Result violantan(@PathVariable Integer id, @PathVariable Short score){
        log.info("学生{}, 扣分{}", id, score);
        studentService.violantan(id, score);
        return Result.success();
    }
}
